package com.cdz.charger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cdz.charger.vo.ChargerTypesVo;
import com.cdz.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.charger.domain.ChargerTypes;
import com.cdz.charger.service.IChargerTypesService;
import com.cdz.common.utils.poi.ExcelUtil;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 充电桩类型Controller
 *
 * @author baefengk2
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/charger/types" )
@Api(tags = "充电桩类型相关接口" )
public class ChargerTypesController extends BaseController {
    @Autowired
    private IChargerTypesService chargerTypesService;

    /**
     * 查询充电桩类型列表
     */
    @PreAuthorize("@ss.hasPermi('charger:types:list')" )
    @GetMapping("/list" )
    @ApiOperation(value = "获取充电桩类型列表" )
    public TableDataInfo<List<ChargerTypes>> list(ChargerTypes chargerTypes) {
        startPage();
        List<ChargerTypes> list = chargerTypesService.selectChargerTypesList(chargerTypes);
        return getDataTable(list);
    }

    /**
     * 导出充电桩类型列表
     */
    @PreAuthorize("@ss.hasPermi('charger:types:export')" )
    @Log(title = "充电桩类型" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    @ApiOperation("导出充电桩类型列表" )
    public void export(HttpServletResponse response, ChargerTypes chargerTypes) {
        List<ChargerTypes> list = chargerTypesService.selectChargerTypesList(chargerTypes);
        ExcelUtil<ChargerTypes> util = new ExcelUtil<ChargerTypes>(ChargerTypes. class);
        util.exportExcel(response, list, "充电桩类型数据" );
    }

    /**
     * 获取充电桩类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('charger:types:query')" )
    @GetMapping(value = "/{id}" )
    @ApiOperation("获取充电桩类型详细信息" )
    public R<ChargerTypes> getInfo(@ApiParam(value = "充电桩类型ID" , required = true)
                                   @PathVariable("id" ) Long id) {
                return R.ok(chargerTypesService.selectChargerTypesById(id));
    }

    /**
     * 新增充电桩类型
     */
    @PreAuthorize("@ss.hasPermi('charger:types:add')" )
    @Log(title = "充电桩类型" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增充电桩类型" )
    public AjaxResult add(@ApiParam(value = "充电桩类型实体" , required = true) @RequestBody ChargerTypes chargerTypes) {
        return toAjax(chargerTypesService.insertChargerTypes(chargerTypes));
    }

    /**
     * 修改充电桩类型
     */
    @PreAuthorize("@ss.hasPermi('charger:types:edit')" )
    @Log(title = "充电桩类型" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改充电桩类型" )
    public AjaxResult edit(@ApiParam(value = "充电桩类型实体" , required = true) @RequestBody ChargerTypes chargerTypes) {
        return toAjax(chargerTypesService.updateChargerTypes(chargerTypes));
    }

    /**
     * 删除充电桩类型
     */
    @PreAuthorize("@ss.hasPermi('charger:types:remove')" )
    @Log(title = "充电桩类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @ApiOperation("删除充电桩类型" )
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组" ) @PathVariable Long[] ids) {
        return toAjax(chargerTypesService.deleteChargerTypesByIds(ids));
    }

    @GetMapping("/all" )
    @ApiOperation("获取所有充电桩类型" )
    public R<List<ChargerTypesVo>> getAllChargerTypes() {
        List<ChargerTypesVo> list = chargerTypesService.getAllChargerTypes();
        return R.ok(list);
    }
}
